#include"string.h"

void test1(){
    //创建s1对象
    Mystring::string s1("hello world");
    //用s1对象拷贝构造s2对象
    Mystring::string s2(s1);
    //将s1对象赋值给s3对象
    Mystring::string s3("hello");
    s3=s1;
}

void test2(){
    Mystring::string s1("hello world");
    //使用opreator[]打印s1
    for(size_t i=0;i<s1.size();i++){
        cout<<s1[i]<<" ";
    }
    cout<<endl;

    //使用普通对象的迭代器打印s1
    Mystring::string::iterator it=s1.begin();
    while(it!=s1.end()){
        cout<<*it<<" ";
        it++;
    }
    cout<<endl;

    //使用const对象的迭代器打印s2
    const Mystring::string s2("hello");
    Mystring::string::const_iterator rit=s2.begin();
    while(rit!=s2.end()){
        cout<<*rit<<" ";
        rit++;
    }
    cout<<endl;
}

void test3(){
    Mystring::string s1("hello world");
    cout<<s1.size()<<" "<<s1.capacity()<<endl;
    //s1容量扩为15
    s1.reserve(15);
    cout<<s1.size()<<" "<<s1.capacity()<<endl;
    //s1容量扩为20，多余空间用字符a填充
    s1.resize(20,'a');
    cout<<s1.size()<<" "<<s1.capacity()<<endl;
    cout<<s1<<endl;
    //s1缩容为8，发生截断
    s1.resize(8);
    cout<<s1.size()<<" "<<s1.capacity()<<endl;
    cout<<s1<<endl;
}

void test4(){
    //创建一个空对象s1
    Mystring::string s1;
    //s1追加字符串hello
    s1.append("hello");
    cout<<s1<<endl;
    //s1追加字符串world
    s1+="world";
    cout<<s1<<endl;
    //s1尾插字符！
    s1.push_back('!');
    cout<<s1<<endl;
    //在s1下标为6的位置插入***
    s1.insert(6,"***");
    cout<<s1<<endl;
    //删除s1下标为10后面的所有字符
    s1.erase(10);
    cout<<s1<<endl;
    //删除s1下标为5后面的三个字符
    s1.erase(5,3);
    cout<<s1<<endl;
}

void test5(){
    Mystring::string s1;
    //输入
    cin>>s1;
    //输出
    cout<<s1<<endl;

}

int main()
{
   //test1();
   //test2();
   //test3();
   //test4();
   //test5();
   return 0;
}
